if ( typeof ( exports ) !== 'undefined' )
{
	var liwe = require ( "./liwe" );
	liwe.types = require ( "./types" );
}


liwe.types.dotdict = function ( d )
{
	this._data = d;
};

liwe.types.dotdict.prototype.get = function ( k, def_val )
{
	if ( ! this._data ) return def_val;

	var keys = liwe.types.list ( k.split ( "." ) );
	var l, curr_key;
	
	try 
	{
		l = this._data;
		keys.iterate ( function ( n )
		{
			curr_key = n;

			l = l [ n ];
		} );

		return l;
	} catch ( e ) {
		console.error ( "dotdict: could not find key: %s (%s)", k, curr_key );
	}

	return def_val;
};

var dotdict = liwe.types.dotdict;


if ( typeof ( exports ) !== 'undefined' ) 
	module.exports = function ( d ) { return new liwe.types.dotdict ( d ); };
